package com.ltg.urban.domain.project.controller;

import com.ltg.framework.annotation.DescribePage4Swagger;
import com.ltg.framework.util.http.PageInfo;
import com.ltg.framework.util.http.PageRequest;
import com.ltg.framework.util.http.Result;
import com.ltg.urban.domain.project.data.request.ApplyCapitalReq;
import com.ltg.urban.domain.project.data.request.ApproveCapitalReq;
import com.ltg.urban.domain.project.data.response.CapitalDetailPageResp;
import com.ltg.urban.domain.project.entity.UrbanProjectCapitalDetail;
import com.ltg.urban.domain.project.service.UrbanProjectCapitalDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p> ClassName: UrbanCapitalApproveController </p>
 * <p> Package: com.ltg.urban.domain.project.controller </p>
 * <p> Description: </p>
 * <p></p>
 *
 * @Author: LTG
 * @Create: 2023/3/1 - 10:34
 * @Version: v1.0
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/capital/detail")
@Tag(name = "资金申请以及审批")
public class UrbanCapitalApproveController {
    private final UrbanProjectCapitalDetailService urbanProjectCapitalDetailService;

    @GetMapping("/query")
    @DescribePage4Swagger
    @Operation(summary = "分页查询:OK")
    public PageInfo<CapitalDetailPageResp> query(HttpServletRequest httpServletRequest) {
        return urbanProjectCapitalDetailService.pageList(PageRequest.buildFromRequest(httpServletRequest));
    }

    @Operation(summary = "员工申请资金:OK")
    @PostMapping("/{capitalId}/apply")
    public Result<UrbanProjectCapitalDetail> employeeApplyCapital(@PathVariable Long capitalId, @RequestBody ApplyCapitalReq req) {
        return urbanProjectCapitalDetailService.employeeApplyCapital(capitalId, req);
    }

    @Operation(summary = "员工资金重新审批:OK")
    @PutMapping("/anewApply/{detailId}")
    public Result<UrbanProjectCapitalDetail> anewApply(@PathVariable Long detailId, @RequestBody ApplyCapitalReq req) {
        return urbanProjectCapitalDetailService.anewApply(detailId, req);
    }


    @Operation(summary = "项目管理员资金审批:OK")
    @PutMapping("/approve/{detailId}")
    public Result<UrbanProjectCapitalDetail> approveCapital(@PathVariable Long detailId, @RequestBody ApproveCapitalReq req) {
        return urbanProjectCapitalDetailService.approveCapital(detailId, req);
    }


}
